home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mush-7.1.1 / doproc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-02  |  21.3 KB  |  815 lines

  1. /* @(#)doproc.c        (c) copyright    10/18/86 (Dan Heller) */
  2.  
  3. /* do main panel item procedures */
  4. #include "mush.h"
  5.  
  6. extern void start_textsw_edit();
  7. void set_comp_items();
  8.  
  9. extern Panel_item
  10.     file_item, folder_text_item, folder_item, msg_num_item, read_item,
  11.     reply_item, save_item, sub_hdr_item[6];
  12.  
  13. /* following macro is for the next two procedures */
  14. #define hdr_item(item) \
  15.     (item == sub_hdr_item[0] || item == sub_hdr_item[1] || \
  16.      item == sub_hdr_item[2] || item == sub_hdr_item[3] || \
  17.      item == sub_hdr_item[4] || item == sub_hdr_item[5])
  18.  
  19. void
  20. delete_mail(item, value, event)
  21. register Panel_item item;
  22. int value;
  23. register Event *event;
  24. {
  25.     int val = value; /* save cuz we reset value immediately */
  26.     u_long bang = ison(glob_flags, IGN_BANG);
  27.     char buf[128];
  28.  
  29.     (void) panel_set(item, PANEL_VALUE, 0, 0);
  30.     if (hdr_item(item) && event_id(event) != MS_LEFT || val == 2) {
  31.     help(0, "delete", tool_help);
  32.     return;
  33.     }
  34.     /* delete current message */
  35.     wprint(sprintf(buf, "\\%sdelete %s\n",
  36.     ((event_id(event) == MS_LEFT || val == 0)? "" : "un"),
  37.     panel_get_value(msg_num_item)) + 1); /* +1 skips the backslash */
  38.     turnon(glob_flags, IGN_BANG);
  39.     (void) cmd_line(buf, msg_list);
  40.     if (!bang)
  41.     turnoff(glob_flags, IGN_BANG);
  42. }
  43.  
  44. void
  45. read_mail(item, value, event)
  46. Panel_item item;
  47. Event *event;
  48. {
  49.     int this_msg = current_msg;
  50.  
  51.     /* check "event" in case we were called from hdr_sw.c
  52.      * in which case event would be NULL
  53.      */
  54.     if (event && event_id(event) == MS_RIGHT && item &&
  55.     (item == read_item ||
  56.     (item == sub_hdr_item[0] || item == sub_hdr_item[1]))) {
  57.     (void) help(0, "next", tool_help);
  58.     return;
  59.     }
  60.     if (item && (item == sub_hdr_item[4] || item == sub_hdr_item[5])) {
  61.     (void) help(0, "Menu Read", tool_help);
  62.     return;
  63.     }
  64.     if (!msg_cnt) {
  65.     wprint ("No Mail.\n");
  66.     return;
  67.     }
  68.     if (item && item == read_item || ison(msg[current_msg].m_flags, DELETE))
  69.     (void) next_msg();
  70.     if (this_msg != current_msg || ison(msg[current_msg].m_flags, UNREAD) ||
  71.         (current_msg < n_array[0] || current_msg > n_array[screen])) {
  72.     set_isread(current_msg);
  73.     (void) do_hdrs(0, DUBL_NULL, NULL);
  74.     }
  75.     if (isoff(msg[current_msg].m_flags, DELETE))
  76.     display_msg(current_msg, (u_long)0);
  77. }
  78.  
  79. /* the panel button that says "filename" and "directory", etc... text item */
  80. Panel_setting
  81. file_dir(item, event)
  82. Panel_item item;
  83. Event *event;
  84. {
  85.     register char *p;
  86.     u_long bang = ison(glob_flags, IGN_BANG);
  87.     char buf[MAXPATHLEN];
  88.  
  89.     if (event_id(event) == ESC) {
  90.     /* file expansion request */
  91.     int n;
  92.     char **files;
  93.     p = panel_get_value(item);
  94.     (void) sprintf(buf, "%s*", p);
  95.     timeout_cursors(1);
  96.     if ((n = filexp(buf, &files)) > 0) {
  97.         Debug("%d: ",n), print_argv(files);
  98.         if (n > 1) {
  99.         n = lcprefix(files, 0);
  100.         files[0][n] = 0;
  101.         }
  102.         panel_set_value(item, trim_filename(files[0]));
  103.         free_vec(files);
  104.     } else
  105.         errbell(n);    /* see curs_io.c */
  106.     timeout_cursors(0);
  107.     return PANEL_NONE;
  108.     }
  109.  
  110.     if (item == folder_text_item) {
  111.     (void) sprintf(buf, "folder %s %s",
  112.         (ison(glob_flags, READ_ONLY) || ison(glob_flags, DO_UPDATE) &&
  113.         !ask("Folder has been modified.  Update changes?"))? "!" : "",
  114.         panel_get_value(folder_text_item));
  115.     }
  116.     else if (item == file_item) {
  117.     register char *b = buf;
  118.     char msgstr[BUFSIZ];
  119.  
  120.     if (event_id(event) == '\n' || event_id(event) == '\r')
  121.         b += Strcpy(buf, "save  ");
  122.     else
  123.         b += Strcpy(buf, "write ");
  124.     if ((p = panel_get_value(msg_num_item)) && *p)
  125.         b += Strcpy(b, p);
  126.     else {
  127.         if (ison(msg[current_msg].m_flags, DELETE) &&
  128.             !do_set(set_options, "show_deleted")) {
  129.         (void) sprintf(msgstr, "Message %d deleted -- save anyway?",
  130.                         current_msg+1);
  131.         if (ask(msgstr) != TRUE) {
  132.             wprint("Message not saved\n");
  133.             return PANEL_NONE;
  134.         }
  135.         }
  136.         b += strlen(sprintf(b, "%d", current_msg+1));
  137.     }
  138.     *b++ = ' ', *b = 0;
  139.     if (!(p = panel_get_value(item)) || !*p &&
  140.         (!(p = do_set(set_options, "mbox")) || !*p))
  141.         p = DEF_MBOX;
  142.     (void) sprintf(msgstr, "%s in \"%s\"?", buf, trim_filename(p));
  143.     if (ask(msgstr) != TRUE) {
  144.         wprint("Message not saved\n");
  145.         return PANEL_NONE;
  146.     }
  147.     (void) strcpy(b, p); /* now add to command */
  148.     }
  149.     turnon(glob_flags, IGN_BANG);
  150.     (void) cmd_line(buf, msg_list);
  151.     if (!bang)
  152.     turnoff(glob_flags, IGN_BANG);
  153.     return PANEL_NONE;
  154. }
  155.  
  156. /*
  157.  * callback routine for the panel items that need filename input.
  158.  * (folder and save)
  159.  */
  160. void
  161. do_file_dir(item, value, event)
  162. Panel_item item;
  163. int value;
  164. Event *event;
  165. {
  166.     char buf[BUFSIZ];
  167.     u_long bang = ison(glob_flags, IGN_BANG);
  168.  
  169.     if (item == folder_item) {
  170.     (void) sprintf(buf, "folder %s ",
  171.         (ison(glob_flags, READ_ONLY) || ison(glob_flags, DO_UPDATE) &&
  172.         !ask("Folder has been modified.  Update changes?"))? "!" : "");
  173.     if (event_id(event) == MS_LEFT) {
  174.         char *p = panel_get_value(folder_text_item);
  175.         if (!*p) {
  176.         ok_box("Enter folder name.");
  177.         return;
  178.         }
  179.         (void) strcat(buf, p);
  180.     } else if (!value)
  181.         (void) strcat(buf, "%");
  182.     else if (value == 1)
  183.         (void) strcat(buf, "&");
  184.     else if (value == 2)
  185.         (void) strcat(buf, "#");
  186.     else
  187.         (void) strcat(buf, panel_get(item, PANEL_CHOICE_STRING, value));
  188.     } else if (item == save_item) {
  189.     char msgstr[BUFSIZ], *p;
  190.     (void) strcpy(buf, "save ");
  191.     if (event_id(event) == MS_LEFT) {
  192.         if (!strcmp("Filename:", panel_get(file_item,PANEL_LABEL_STRING))) {
  193.         event_id(event) = '\n';  /* let file_dir think it got a \n */
  194.         file_dir(file_item, event);
  195.         return;
  196.         }
  197.     } else if (value == 0) {
  198.         register char *p2 = (char *)panel_get_value(msg_num_item);
  199.  
  200.         if (!(p = do_set(set_options, "mbox")) || !*p)
  201.         p = DEF_MBOX;
  202.         if (p2 && *p2) {
  203.         (void) strcat(buf, p2);
  204.         (void) strcat(buf, " ");
  205.         }
  206.         (void) strcat(buf, p);
  207.     } else
  208.         (void) strcat(buf, p = panel_get(item, PANEL_CHOICE_STRING, value));
  209.     (void) sprintf(msgstr, "Save in %s? ", trim_filename(p));
  210.     if (ask(msgstr) != TRUE) {
  211.         wprint("Message not saved\n");
  212.         return;
  213.     }
  214.     }
  215.     turnon(glob_flags, IGN_BANG);
  216.     (void) cmd_line(buf, msg_list);
  217.     if (!bang)
  218.     turnoff(glob_flags, IGN_BANG);
  219.     (void) panel_set(item, PANEL_VALUE, 0, NULL); /* remove last value */
  220. }
  221.  
  222. /*ARGSUSED*/
  223. void
  224. do_help(item, value, event)
  225. Panel_item item;
  226. register int value;
  227. Event *event;
  228. {
  229.     register char *p, *helpfile = tool_help;
  230.     if (!event || event_id(event) == MS_LEFT)
  231.     value = 0;
  232.     switch(value) {
  233.     case 1: p = "help";
  234.     when 2: p = "mouse";
  235.     when 3: p = "windows";
  236.     when 4: p = "hdr_format", helpfile = cmd_help;
  237.     when 5: p = "msg_list", helpfile = cmd_help;
  238.     when 6: p = "folder";
  239.     otherwise: p = "general";
  240.     }
  241.     (void) help(0, p, helpfile);
  242. }
  243.  
  244. /*ARGSUSED*/
  245. void
  246. do_update(item, value, event)
  247. Panel_item item;
  248. int value;
  249. Event *event;
  250. {
  251.     char *argv[2];
  252.     if (event && event_id(event) != MS_LEFT) {
  253.     if (value == 0) {
  254.         if (check_new_mail() == 0)
  255.         print("No new mail.\n");
  256.     } else
  257.         (void) help(0, "update", tool_help);
  258.     return;
  259.     }
  260.     argv[0] = "update";
  261.     argv[1] = NULL;
  262.     timeout_cursors(TRUE);
  263.     (void) folder(0, argv, NULL);
  264.     timeout_cursors(FALSE);
  265. }
  266.  
  267. /*ARGSUSED*/
  268. void
  269. toolquit(item, value, event)
  270. Panel_item item;
  271. int value;
  272. Event *event;
  273. {
  274.     void wmgr_changestate(), wmgr_changelevel();
  275.     register int which;
  276.  
  277.     if (!value || event_id(event) == MS_LEFT) {
  278.     if (ison(glob_flags, DO_UPDATE)) {
  279.         do_update(NO_ITEM, 0, NO_EVENT);
  280.         turnoff(glob_flags, NEW_MAIL);
  281.     }
  282.     check_icons();
  283.     mail_status(0); /* lower flag (if up) print current num of msgs */
  284.     /* wmgr_changestate (window_get(tool, WIN_FD), rootfd, TRUE); */
  285.     /* wmgr_changelevel (window_get(tool, WIN_FD), parentfd, TRUE); */
  286.     window_set(tool, FRAME_CLOSED, TRUE, NULL);
  287.     is_iconic = ((int) window_get(tool, FRAME_CLOSED));
  288.     return;
  289.     } else if (value == 2) {
  290.     (void) help(0, "quit", tool_help);
  291.     return;
  292.     }
  293.     /* modify this to check for "abort" choice when ternary return values
  294.      * are possible!
  295.      */
  296.     if (isoff(glob_flags, DO_UPDATE) ||
  297.         ask("Folder has been modified -- update?")) {
  298.     if (!copyback("Quit anyway?"))
  299.         return;
  300.     }
  301.     cleanup(0);
  302. }
  303.  
  304. /*ARGSUSED*/
  305. void
  306. do_lpr(item, value, event)
  307. Panel_item item;
  308. int value;
  309. Event *event;
  310. {
  311.     char buf[128];
  312.  
  313.     if (event && (event_id(event) == MS_LEFT || value == 1)) {
  314.     wprint("Sending message %d to printer...\n", current_msg+1);
  315.     (void) strcpy(buf, "lpr ");
  316.     if (value)
  317.         (void) sprintf(buf, "lpr \"%s\"", panel_get_value(msg_num_item));
  318.     timeout_cursors(TRUE);
  319.     (void) cmd_line(buf, msg_list);
  320.     timeout_cursors(FALSE);
  321.     } else
  322.     (void) help(0, "printer", tool_help);
  323. }
  324.  
  325. /* panel selection button pressed to send a letter.
  326.  * we've attached the sign panel item to this item to 1) avoid
  327.  * using a global and 2) make it general enough so that multiple
  328.  * compose windows can have multiple send_items and we can
  329.  * identify which sign/fortune items are associated with this
  330.  * particular letter.  The fortune item is attached to the sign
  331.  * item.
  332.  */
  333. /*ARGSUSED*/
  334. void
  335. do_send(item, value, event)
  336. Panel_item item;
  337. int value;
  338. register Event *event;
  339. {
  340.     Panel panel = (Panel)panel_get(item, PANEL_PARENT_PANEL);
  341.     Panel_item sign_item = (Panel_item)panel_get(item, PANEL_CLIENT_DATA);
  342.     Panel_item fortune_item =
  343.     (Panel_item)panel_get(sign_item, PANEL_CLIENT_DATA);
  344.     Textsw textsw = (Textsw)panel_get(panel, PANEL_CLIENT_DATA);
  345.     char *argv[5], buf[64];
  346.     char *file = (char *)window_get(textsw, TEXTSW_CLIENT_DATA);
  347.     char *p, *oldsign = NULL, *oldfortune = NULL;
  348.     Textsw save_sw = wprint_sw;
  349.  
  350.     if (textsw_store_file(textsw, file, 0, 0)) {
  351.     error("Can't save to %s", file);
  352.     return;
  353.     }
  354.     /* check if user changed variables before sending */
  355.     if (p = do_set(set_options, "autosign"))
  356.     oldsign = savestr(p);
  357.     if (panel_get_value(sign_item) && !oldsign)
  358.     cmd_line(strcpy(buf, "\\set autosign"), NULL);
  359.     else if (!panel_get_value(sign_item) && oldsign)
  360.     cmd_line(strcpy(buf, "\\unset autosign"), NULL);
  361.     if (p = do_set(set_options, "fortune"))
  362.     oldfortune = savestr(p);
  363.     if (panel_get_value(fortune_item) && !oldfortune)
  364.     (void) cmd_line(strcpy(buf, "set fortune"), NULL);
  365.     else if (!panel_get_value(fortune_item) && oldfortune)
  366.     (void) cmd_line(strcpy(buf, "\\unset fortune"), NULL);
  367.     wprint_sw = NULL;
  368.     wprint_sw = save_sw;
  369.     turnoff(glob_flags, IS_GETTING);
  370.     argv[0] = "mail";
  371.     argv[1] = "-Uh";
  372.     argv[2] = file;
  373.     argv[3] = NULL;
  374.     clear_msg_list(msg_list);
  375.     timeout_cursors(TRUE);
  376.     if (do_mail(3, argv, msg_list) == 0) {
  377.     (void) unlink(file);
  378.     set_comp_items(panel);
  379.     }
  380.     if (panel_get_value(sign_item) && !oldsign)
  381.     (void) cmd_line(strcpy(buf, "\\unset autosign"), NULL);
  382.     else if (!panel_get_value(sign_item) && oldsign) {
  383.     argv[0] = "set";
  384.     argv[1] = "autosign";
  385.     if (*oldsign) {
  386.         argv[2] = "=";
  387.         argv[3] = oldsign;
  388.         argv[4] = NULL;
  389.         (void) set(4, argv, NULL);
  390.     } else {
  391.         argv[2] = NULL;
  392.         (void) set(2, argv, NULL);
  393.     }
  394.     }
  395.     if (panel_get_value(fortune_item) && !oldfortune)
  396.     cmd_line(strcpy(buf, "\\unset fortune"), NULL);
  397.     else if (!panel_get_value(fortune_item) && oldfortune) {
  398.     argv[0] = "set";
  399.     argv[1] = "fortune";
  400.     if (*oldfortune) {
  401.         argv[2] = "=";
  402.         argv[3] = oldfortune;
  403.         argv[4] = NULL;
  404.         (void) set(4, argv, NULL);
  405.     } else {
  406.         argv[2] = NULL;
  407.         (void) set(2, argv, NULL);
  408.     }
  409.     }
  410.     xfree(oldsign), xfree(oldfortune);
  411.     timeout_cursors(FALSE);
  412. }
  413.  
  414. /*ARGSUSED*/
  415. void
  416. do_include(item, value, event)
  417. Panel_item item;
  418. int value;
  419. Event *event;
  420. {
  421.     extern FILE *ed_fp;
  422.     char *p, buf[64], *file;
  423.     Textsw textsw = (Textsw)panel_get(panel_get(item, PANEL_PARENT_PANEL),
  424.     PANEL_CLIENT_DATA);
  425.  
  426.     if (event && event_id(event) == MS_LEFT)
  427.     value = 0;
  428.     if (value == 2) {
  429.     (void) help(0, "include", tool_help);
  430.     return;
  431.     }
  432.     p = panel_get_value(msg_num_item);
  433.     (void) sprintf(buf, "%c%c%s", *escape, value == 0? 'i' : 'f', p? p : "");
  434.  
  435.     file = (char *)window_get(textsw, TEXTSW_CLIENT_DATA);
  436.     if (textsw_store_file(textsw, file, 0, 0)) {
  437.     (void) ask("Something's wrong... Click anything.");
  438.     return;
  439.     }
  440.     if (ed_fp) {
  441.     (void) ask("tmpfile already in use... Click anything.");
  442.     (void) fclose(ed_fp);
  443.     }
  444.     if (!(ed_fp = mask_fopen(file, "a"))) {
  445.     error("Cannot open %s to append msg.", file);
  446.     return;
  447.     }
  448.     (void) add_to_letter(buf);
  449.     (void) fclose(ed_fp), ed_fp = NULL_FILE;
  450. #ifdef SUN_4_0 /* SunOS 4.0+ */
  451.     window_set(textsw, TEXTSW_FILE_CONTENTS, file, NULL);
  452. #else /* SUN_4_0 */
  453.     textsw_load_file(textsw, file, 1, 0, 0);
  454. #endif /* SUN_4_0 */
  455.     window_set(textsw, TEXTSW_UPDATE_SCROLLBAR, NULL);
  456.     (void) unlink(file);
  457. }
  458.  
  459. /*ARGSUSED*/
  460. void
  461. do_compose(item, value, event)
  462. Panel_item item;
  463. int value;
  464. Event *event;
  465. {
  466.     char buf[5];
  467.     Textsw textsw;
  468.  
  469.     if (event && event_id(event) != MS_LEFT) {
  470.     (void) help(0, "compose", tool_help);
  471.     return;
  472.     }
  473.     open_compose();
  474.     clear_msg_list(msg_list);
  475.     if (do_mail(0, DUBL_NULL, msg_list) == 0) {
  476. #ifdef SUN_4_0
  477.     Panel panel = (Panel)window_get(compose_frame, FRAME_NTH_WINDOW, 1);
  478. #else
  479.     Panel panel = (Panel)window_get(compose_frame, FRAME_NTH_WINDOW, 0);
  480. #endif /* SUN_4_0 */
  481.     Textsw textsw = (Textsw)panel_get(panel, PANEL_CLIENT_DATA);
  482.     start_textsw_edit(textsw, TRUE);
  483.     set_comp_items(panel);
  484.     }
  485. }
  486.  
  487. /*
  488.  * notify proc for reply button -- also called from select.c (do_menu()) ,
  489.  * in which case "event" is null and "value" contains the message
  490.  * number of the message to reply to.
  491.  */
  492. /*ARGSUSED*/
  493. void
  494. respond_mail(item, value, event)
  495. Panel_item item;
  496. int value;
  497. Event *event;
  498. {
  499.     int tmp = current_msg;
  500.     char buf[256];
  501.  
  502.     if (event && event_id(event) == MS_LEFT)
  503.     value = 0;
  504.     if (event && value == 4) {
  505.     (void) help(0, "respond", tool_help);
  506.     return;
  507.     }
  508.     if (!msg_cnt) {
  509.     wprint("No messages to respond to.\n");
  510.     return;
  511.     }
  512.     if (ison(glob_flags, IS_GETTING)) {
  513.     wprint("Finish editing current message first.\n");
  514.     return;
  515.     }
  516.     if (!event)
  517.     tmp = value, value = 0;
  518.     open_compose();
  519.     (void) sprintf(buf, "%s %s %d",
  520.     (value == 2 || value == 3)? "\\replyall" : "\\replysender",
  521.     (value == 1 || value == 3)? "-i": NO_STRING, tmp+1);
  522.     if (cmd_line(buf, NULL) != -1) {
  523. #ifdef SUN_4_0
  524.     Panel panel = (Panel)window_get(compose_frame, FRAME_NTH_WINDOW, 1);
  525. #else
  526.     Panel panel = (Panel)window_get(compose_frame, FRAME_NTH_WINDOW, 0);
  527. #endif /* SUN_4_0 */
  528.     Textsw textsw = (Textsw)panel_get(panel, PANEL_CLIENT_DATA);
  529.     wprint("Responding to message %d\n", tmp+1);
  530.     start_textsw_edit(textsw, FALSE);
  531.     set_comp_items(panel);
  532.     }
  533. }
  534.  
  535. /*ARGSUSED*/
  536. void
  537. load_from_file(item, value, event)
  538. Panel_item item;
  539. int value;
  540. Event *event;
  541. {
  542.     int x = 0;
  543.     Textsw textsw;
  544.     Panel_item filename_item = (Panel_item)panel_get(item, PANEL_CLIENT_DATA);
  545.     char *file, *p = panel_get_value(filename_item);
  546. #ifndef SUN_4_0 /* SunOS 4.0+ */
  547.     char *sfile, buf[128];
  548.     extern FILE *ed_fp;
  549. #endif /* SUN_4_0 */
  550.     
  551.     if (!*p) {
  552.     wprint("Specify Filename.\n");
  553.     return;
  554.     }
  555.     file = getpath(p, &x);
  556.     if (x == 1)
  557.     wprint("%s: is a directory.\n", p);
  558.     else if (x == -1)
  559.     wprint("%s: %s\n", p, file);
  560.     if (x)
  561.     return;
  562.     timeout_cursors(TRUE);
  563.     textsw = (Textsw)panel_get(panel_get(item, PANEL_PARENT_PANEL),
  564.     PANEL_CLIENT_DATA);
  565.     if (event_id(event) != MS_LEFT && value == 1)
  566.     /* replace */
  567.     textsw_load_file(textsw, file, 1, 0, 0);
  568.     else {
  569.     /* insert */
  570. #ifdef SUN_4_0 /* SunOS 4.0+ */
  571.     window_set(textsw, TEXTSW_INSERT_FROM_FILE, file, NULL);
  572. #else /* SUN_4_0 */
  573.     /* best we can do with pre 4.0 is save the current file
  574.      * and append the new file onto the end.
  575.      */
  576.     sfile = (char *)window_get(textsw, TEXTSW_CLIENT_DATA);
  577.     if (textsw_store_file(textsw, sfile, 0, 0)) {
  578.         (void) ask("Can't save file... Click anything.");
  579.         return;
  580.     }
  581.     if (ed_fp) {
  582.         (void) ask("tmpfile already in use... Click anything.");
  583.         fclose(ed_fp);
  584.     }
  585.     if (!(ed_fp = mask_fopen(sfile, "a"))) {
  586.         error("Cannot open %s.", sfile);
  587.         return;
  588.     }
  589.     (void) sprintf(buf, "%c%c%s", *escape, 'r', trim_filename(p));
  590.     (void) add_to_letter(buf);
  591.     (void) fclose(ed_fp), ed_fp = NULL_FILE;
  592.     textsw_load_file(textsw, sfile, 1, 0, 0);
  593.     (void) unlink(sfile);
  594. #endif /* SUN_4_0 */
  595.     }
  596.     window_set(textsw, TEXTSW_UPDATE_SCROLLBAR, NULL);
  597.     panel_set_value(item, 0);
  598.     timeout_cursors(FALSE);
  599. }
  600.  
  601. /*ARGSUSED*/
  602. void
  603. save_to_file(item, value, event)
  604. Panel_item item;
  605. Event *event;
  606. {
  607.     Panel_item filename_item = panel_get(item, PANEL_CLIENT_DATA);
  608.     char *file = panel_get_value(filename_item);
  609.     FILE *fp;
  610.     Textsw textsw = (Textsw)panel_get(panel_get(item, PANEL_PARENT_PANEL),
  611.     PANEL_CLIENT_DATA);
  612.  
  613.     if (!*file) {
  614.     wprint("Specify Filename\n");
  615.     return;
  616.     }
  617.     timeout_cursors(TRUE);
  618.     /* append to file -- no confirmation necessary */
  619.     if (fp = open_file(file, FALSE, TRUE)) {
  620.     char buf[BUFSIZ];
  621.     Textsw_index next_pos = 0, tmp;
  622.     Textsw_index length =
  623.         (Textsw_index)window_get(textsw, TEXTSW_LENGTH);
  624.     do  {
  625.         tmp = next_pos;
  626.         next_pos = (Textsw_index) window_get(textsw, TEXTSW_CONTENTS,
  627.         next_pos, buf, sizeof(buf));
  628.         if (fwrite(buf, sizeof(char), (int)(next_pos - tmp), fp) == 0)
  629.         error("%s may be incomplete", file);
  630.     } while (next_pos < length);
  631.     (void) close_lock(file, fp);
  632.     wprint("Wrote %d bytes to %s\n", length, trim_filename(file));
  633.     }
  634.     timeout_cursors(FALSE);
  635. }
  636.  
  637. void
  638. abort_mail(item, event)
  639. Panel_item item;
  640. Event *event;
  641. {
  642.     Panel panel = (Panel)panel_get(item, PANEL_PARENT_PANEL);
  643.     Textsw textsw = (Textsw)panel_get(panel, PANEL_CLIENT_DATA);
  644.     wprint("Aborted letter.\n");
  645.     textsw_reset(textsw, 0, 0);
  646.     rm_edfile(0);
  647.     set_comp_items(panel);
  648. }
  649.  
  650. /* set the compose panel items */
  651. void
  652. set_comp_items(panel)
  653. Panel panel;
  654. {
  655.     Panel_item item, next;
  656.     Textsw textsw = (Textsw)panel_get(panel, PANEL_CLIENT_DATA);
  657.     int getting = ison(glob_flags, IS_GETTING) != 0;
  658.     int i = 0;
  659.  
  660.     window_set(textsw, TEXTSW_READ_ONLY, !getting, NULL);
  661.     /* remove next line when multiple composes become a reality */
  662.     (void) panel_set(reply_item, PANEL_SHOW_ITEM, !getting, NULL);
  663.     /* skip "close" item */
  664.     item = (Panel_item) panel_get(panel, PANEL_FIRST_ITEM);
  665.     for (item = (Panel_item) panel_get(item, PANEL_NEXT_ITEM);
  666.     item; item = next) {
  667.     next = (Panel_item) panel_get(item, PANEL_NEXT_ITEM);
  668.     (void) panel_set(item,
  669.         PANEL_SHOW_ITEM, (i++ < 1)? !getting : getting, NULL);
  670.     }
  671. }
  672.  
  673. /*
  674.  * Ask a yes/no question and return an answer: TRUE or FALSE.
  675.  */
  676. ask(question)
  677. char *question;
  678. {
  679. #ifdef SUN_4_0 /* SunOS 4.0+ */
  680.     return alert_prompt(tool, (Event *)NULL,
  681.     ALERT_MESSAGE_STRINGS,    question, NULL,
  682.     ALERT_BUTTON_YES,    "Yes",
  683.     ALERT_BUTTON_NO,    "No",
  684.     NULL) == ALERT_YES;
  685. #else /* SUN_4_0 */
  686.     Event event;
  687.     struct prompt prompt;
  688.     Rect *rect = (Rect *)window_get(tool, WIN_RECT);
  689.     char buf[MAXPATHLEN];
  690.  
  691.     (void) sprintf(buf,
  692.         "%s  \nPress LEFT Button to Confirm.  Anything else to cancel.",
  693.         question);
  694.     prompt.prt_rect.r_left = rect->r_left + (rect->r_width / 3);
  695.     prompt.prt_rect.r_top = rect->r_top + (rect->r_height / 3);
  696.     prompt.prt_rect.r_width = prompt.prt_rect.r_height = PROMPT_FLEXIBLE;
  697.     prompt.prt_font = mush_font;
  698.     prompt.prt_text = buf;
  699.  
  700.     menu_prompt(&prompt, &event, window_get(tool, WIN_FD));
  701.     return event_id(&event) == MS_LEFT;
  702. #endif /* SUN_4_0 */
  703. }
  704.  
  705. void
  706. ok_box(buf)
  707. char *buf;
  708. {
  709. #ifdef SUN_4_0
  710.     (void) alert_prompt(tool, (Event *)NULL,
  711.     ALERT_MESSAGE_STRINGS,    buf, NULL,
  712.     ALERT_BUTTON_YES,        "Ok",
  713.     NULL);
  714. #else /* SUN_4_0 */
  715.     Event event;
  716.     struct prompt prompt;
  717.     Rect *rect = (Rect *)window_get(tool, WIN_RECT);
  718.     (void) strcat(buf, "  \nPress LEFT Button to Continue.");
  719.     prompt.prt_rect.r_left = rect->r_left + (rect->r_width / 3);
  720.     prompt.prt_rect.r_top = rect->r_top + (rect->r_height / 3);
  721.     prompt.prt_rect.r_width = prompt.prt_rect.r_height = PROMPT_FLEXIBLE;
  722.     prompt.prt_font = mush_font;
  723.     prompt.prt_text = buf;
  724.     menu_prompt(&prompt, &event, window_get(tool, WIN_FD));
  725. #endif /* SUN_4_0 */
  726. }
  727.  
  728. Panel_setting
  729. msg_num_done(item, event)
  730. Panel_item item;
  731. Event *event;
  732. {
  733.     char buf[82];
  734.     u_long bang = ison(glob_flags, IGN_BANG);
  735.     register char *p;
  736.     int n;
  737.  
  738.     if (event_id(event) != '\n' && event_id(event) != '\r') {
  739.     (void) help(0, "message range", tool_help);
  740.     return PANEL_NONE;
  741.     }
  742.     (void) sprintf(buf, "headers %s", (p = (char *)panel_get_value(item)));
  743.     (void) panel_set(item, PANEL_VALUE, NO_STRING, NULL);
  744.     if (!(n = chk_msg(p)))
  745.     return PANEL_NONE;
  746.     current_msg = --n;
  747.     turnon(glob_flags, IGN_BANG);
  748.     (void) cmd_line(buf, msg_list);
  749.     if (!bang)
  750.     turnoff(glob_flags, IGN_BANG);
  751.     (void) display_msg(n, (u_long)0);
  752.     return PANEL_NONE;
  753. }
  754.  
  755. void
  756. do_sort(item, value, event)
  757. Panel_item item;
  758. int value;
  759. Event *event;
  760. {
  761.     char *argv[3], list[MAXMSGS_BITS];
  762.     char *p = (char *)panel_get_value(msg_num_item);
  763.     int n = 0;
  764.  
  765.     if (p && *p) {
  766.     argv[0] = p;
  767.     argv[1] = NULL;
  768.     n = get_msg_list(argv, list);
  769.     }
  770.     argv[0] = "sort";
  771.     argv[2] = NULL;
  772.  
  773.     if (event_id(event) == MS_LEFT)
  774.     argv[1] = do_set(set_options, "sort");
  775.     else switch(value) {
  776.     case 0: argv[1] = "d";
  777.     when 1: argv[1] = "a";
  778.     when 2: argv[1] = "l";
  779.     when 3: argv[1] = "R";
  780.     when 4: argv[1] = "s";
  781.     when 5: argv[1] = "S";
  782.     when 6: (void) help(0, "sort", tool_help);
  783.     }
  784.     if (value != 6) {
  785.     if (n > 0) {
  786.         turnon(glob_flags, IS_PIPE);
  787.         (void) sort(2, argv, list);
  788.         turnoff(glob_flags, IS_PIPE);
  789.     } else
  790.         (void) sort(2, argv, NULL);
  791.     (void) do_hdrs(0, DUBL_NULL, NULL);
  792.     }
  793.     (void) panel_set(item, PANEL_VALUE, 0, NULL);
  794. }
  795.  
  796. void
  797. do_options(item, value, event)
  798. Panel_item item;
  799. int value;
  800. Event *event;
  801. {
  802.     if (event_id(event) == MS_LEFT) {
  803.     view_options();
  804.     return;
  805.     }
  806.     switch (value) {
  807.     case 0:
  808.         view_options();
  809.     when 1:
  810.         do_ignore();
  811.     when 2:
  812.         do_aliases();
  813.     }
  814. }
  815.